﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
using System.Web.UI;using System.Web.UI.WebControls;
namespace ZLDC.Topo.BLL.Estate
{
    public class lp_Configuration
    {
        public static void GetList(Repeater RpList,string deptid)
        {
                        string sql = "select * from lp_Configuration_main where deptID=" + deptid + " and DATEDIFF(dd, workday, '" + DateTime.Now.ToString("yyyy-MM-dd") + "') = 0 ";
            DataSet ds1 = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            RpList.DataSource = ds1;
            RpList.DataBind();
           
            foreach (RepeaterItem Item in RpList.Items)
            {
                HiddenField hidid = (HiddenField)Item.FindControl("hidid");                CheckBox chk = (CheckBox)Item.FindControl("CheckBox2");
                CheckBox chk1 = (CheckBox)Item.FindControl("CheckBox1");
                TextBox txtRemark = (TextBox)Item.FindControl("txtRemark");
                HiddenField hidSoure = (HiddenField)Item.FindControl("hidSoure");
                HiddenField hidmain_id = (HiddenField)Item.FindControl("hidmain_id");
                HiddenField hidworkday = (HiddenField)Item.FindControl("hidworkday");
                HiddenField hidtf = (HiddenField)Item.FindControl("hidtf");                string sql_reply = "select * from lp_main_Reply where Configuration_mainID=" + hidmain_id.Value + " and UserObj=" + hidid.Value + " and CreateUserID=" + _Utility.GetInfoBySession().m_sUserID + " and txtTime='" + Convert.ToDateTime(hidworkday.Value).ToString("yyyy-MM-dd") + "' order by createtime desc";
                ds1 = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql_reply);
                if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds1))
                {
                    txtRemark.Text = ds1.Tables[0].Rows[0]["Reply"].ToString();
                    hidtf.Value = "1";
                }
            }
            
        }

        public static void BtnAdd(Repeater RpList, int Ppcount, int Pcount,Page p,string deptid)
        {
            string sql = "";
            string sql_reply = "";
            DateTime today = DateTime.Now;            string createUser = _Utility.GetInfoBySession().m_sUserID;            foreach (RepeaterItem Item in RpList.Items)
            {
                HiddenField hidid = (HiddenField)Item.FindControl("hidid");                HiddenField hiddeptid = (HiddenField)Item.FindControl("hiddeptid");                CheckBox chk = (CheckBox)Item.FindControl("CheckBox2");
                CheckBox chk1 = (CheckBox)Item.FindControl("CheckBox1");
                TextBox txtRemark = (TextBox)Item.FindControl("txtRemark");
                HiddenField hidSoure = (HiddenField)Item.FindControl("hidSoure");
                HiddenField hidmain_id = (HiddenField)Item.FindControl("hidmain_id");
                HiddenField hidtf = (HiddenField)Item.FindControl("hidtf");                if (hidSoure.Value != "1")
                {
                    if (chk.Checked || chk1.Checked)
                    {
                                                                                                                                                                                                sql += "update lp_Configuration_main set ";
                        sql += "workDay='" + today + "',userID=" + hidid.Value + ",deptid=" + hiddeptid.Value + ",total=0,sureScore=0,color=1,isConfirm=" + (chk1.Checked == true ? "1" : "0") + ",isComplete=0,";
                        sql += "leave=" + (chk1.Checked == true ? "1" : "0") + ",choiceType=" + (chk.Checked == true ? "1" : "0") + ",remark='" + txtRemark.Text + "',";
                        sql += "createTime='" + today + "',createUser='" + _Utility.GetInfoBySession().m_sUserID + "',Other1='" + (chk.Checked == true ? "1" : "0") + "'";
                        sql += " where workDay='" + today.ToString("yyyy-MM-dd") + "' and userID=" + hidid.Value + " ";
                        Ppcount++;
                        #region 添加或者修改 工作意见
                        if (txtRemark.Text != "")
                        {
                            if (hidtf.Value != "1")
                            {
                                sql_reply += "insert into lp_main_Reply (Configuration_mainID,Reply,MainID,DeptID,DeptName,Station,CreateTime,CreateName,txtTime,CreateUserid,UserObj) "
                                       + " values ("
                                       + " " + hidmain_id.Value + ",'" + txtRemark.Text + "',0," + _Utility.GetInfoBySession().m_sDeptID + ",'" + _Utility.GetInfoBySession().m_sDeptName + "',"
                                       + " '" + _Utility.GetInfoBySession().m_sStation + "' , '" + DateTime.Now + "','" + _Utility.GetInfoBySession().m_sUserName + "','" + today.ToString("yyyy-MM-dd") + "'," + _Utility.GetInfoBySession().m_sUserID + "," + hidid.Value + ""
                                       + ");";
                            }
                            else
                            {
                               
                                sql_reply += "update lp_main_Reply set Reply='" + txtRemark.Text + "',UpdateTime='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where  Configuration_mainID=" + hidmain_id.Value + " and UserObj=" + hidid.Value + " and CreateUserID=" + _Utility.GetInfoBySession().m_sUserID + " and Convert(varchar,txtTime,23)='" + today.ToString("yyyy-MM-dd") + "'";
                            }
                        }
                        #endregion
                    }
                    Ppcount++;
                                                                            }
                else
                {
                    sql += "update lp_Configuration_main set ";
                    sql += "isConfirm=" + (chk1.Checked == true ? "1" : "0") + ",";
                    sql += "leave=" + (chk1.Checked == true ? "1" : "0") + ",choiceType=" + (chk.Checked == true ? "1" : "0") + ",remark='" + txtRemark.Text + "',";
                    sql += "createUser='" + _Utility.GetInfoBySession().m_sUserID + "',Other1='" + (chk.Checked == true ? "1" : "0") + "'";
                    sql += " where workDay='" + today.ToString("yyyy-MM-dd") + "' and userID=" + hidid.Value + " ";
                    #region
                    if (txtRemark.Text != "")
                    {
                        if (hidtf.Value != "1")
                        {
                            sql_reply += "insert into lp_main_Reply (Configuration_mainID,Reply,MainID,DeptID,DeptName,Station,CreateTime,CreateName,txtTime,CreateUserid,UserObj) "
                                      + " values ("
                                      + " " + hidmain_id.Value + ",'" + txtRemark.Text + "',0," + _Utility.GetInfoBySession().m_sDeptID + ",'" + _Utility.GetInfoBySession().m_sDeptName + "',"
                                      + " '" + _Utility.GetInfoBySession().m_sStation + "' , '" + DateTime.Now + "','" + _Utility.GetInfoBySession().m_sUserName + "','" + today.ToString("yyyy-MM-dd") + "'," + _Utility.GetInfoBySession().m_sUserID + "," + hidid.Value + ""
                                      + ");";
                        }
                        else
                        {
                            sql_reply += "update lp_main_Reply set Reply='" + txtRemark.Text + "',UpdateTime='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where  Configuration_mainID=" + hidmain_id.Value + " and UserObj=" + hidid.Value + " and CreateUserID=" + _Utility.GetInfoBySession().m_sUserID + " and Convert(varchar,txtTime,23)='" + today.ToString("yyyy-MM-dd") + "'";
                        }
                    }
                    #endregion
                }
            }
            if (sql != "")
            {
                ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql+sql_reply);
            }
            string alert = "";
                                                                                        alert = "保存成功！";
                            p.Response.Write("<script>alert('" + alert + "！');window.location.href=location.href;</script>");
            }

          
        }
}
